package com.Logistics.controller;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

@RestController
@RequestMapping("/jishu")
public class XjishuC {
    @PostMapping("/yzm/{sjh}")
    HashMap<String,Object> yzm(@PathVariable String sjh)throws Exception{//发送验证码
        int randomCode = new Random().nextInt(999999 - 100000 + 1) + 100000;
        System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
        System.setProperty("sun.net.client.defaultReadTimeout", "10000");
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI5tHRyH5Ms3SoJgsF6okS", "PEpm2ZpL9YDUPjX34WttmQXbyjJxWR");
        DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Dysmsapi", "dysmsapi.aliyuncs.com");
        SendSmsRequest request = new SendSmsRequest();
        request.setPhoneNumbers(sjh);
        request.setSignName("JYG项目短信");
        request.setTemplateCode("SMS_465630287");
        request.setTemplateParam("{\"code\":\"" + randomCode + "\"}");
        request.setOutId("yourOutId");
        SendSmsResponse sendSmsResponse = new DefaultAcsClient(profile).getAcsResponse(request);
        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put("jg", sendSmsResponse);
        resultMap.put("yzm", randomCode);
        resultMap.put("sjh", sjh);
        return resultMap;
    }
}
